import {createRouter, createWebHistory} from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import {userStore} from "../stores/user.js";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {path:'/login',component:Login},
        {path:'/home',component:Home},
    ]
})

router.beforeEach((to, from, next) => {
    const store =userStore()
    const token = store.token
    if (to.path === '/login' || token) {
        next()
    } else {
        next({path: '/login'})
    }
})
export default router